#if 0
#include "rtssl_c.hpp"
// gcc demo_rtssl_c.c -lcrypto -std=c99
#else
#include "rtssl_c.h"
// gcc demo_rtssl_c.c rtssl_c.c -lcrypto -std=c99
#endif

#define BUFFER_LEN 256
#define STRING_KEY "ABCdef123"


int main(int argc, char* argv[])		// RSA写入文件，并分别用两个程序存/读
{
	char from[BUFFER_LEN];
	if(argc>1)  strcpy(from, argv[1]);
	else  strcpy(from, "This is a test.");

	char cipher[BUFFER_LEN] = {0};
	char clear[BUFFER_LEN] = {0};

	TRY(Except_SSL){
		// MD5 测试
		md5_string(cipher, from, strlen(from));
		md5_file(clear, "../config/pub.pem");
		printf("【MD5】 Test: \nstring MD5 : %s\nfile MD5 : %s\n", cipher, clear);

		// Base64 编码测试
		encode_base64(cipher, from, strlen(from));
		decode_base64(clear, cipher, strlen(cipher));
		printf("【Base64】 Test: \nCipher : %s\nClear : %s\n", cipher, clear);

		// DES 对称加密
		encrypt_des(cipher, from, strlen(from), STRING_KEY);
		decrypt_des(clear, cipher, strlen(cipher), STRING_KEY);
		printf("【DES】 Test: \nCipher : %s\nClear : %s\n", cipher, clear);

		// RSA 非对称加密
		RSA* pubkey = rsa_load_keyfile("../config/pub.pem", true);
		RSA* privkey = rsa_load_keyfile("../config/priv.pem", false);
		// RSA 公钥加密
		encrypt_rsa_pubkey(cipher, from, strlen(from), pubkey);
		decrypt_rsa_privkey(clear, cipher, strlen(cipher), privkey);
		printf("【RSA_PublicKey_Encrypt】 Test: \nCipher : %s\nClear : %s\n", cipher, clear);
		// RSA 私钥加密
		encrypt_rsa_privkey(cipher, from, strlen(from), privkey);
		decrypt_rsa_pubkey(clear, cipher, strlen(cipher), pubkey);
		printf("【RSA_PrivateKey_Encrypt】 Test: \nCipher : %s\nClear : %s\n", cipher, clear);
		// RSA 释放秘钥内存
		rsa_free_keyfile(pubkey);
		rsa_free_keyfile(privkey);

	}CATCH(RSA_PrivKey_Enc_Err){
		_print("RSA_PrivKey_Enc_Err");
		printf(Except_SSL.description);
		exit(1);
	}ELSE{
		_print("Else Error.");
		printf(Except_SSL.description);
		exit(1);
	}ENDTRY
}